package com.laiketui.app.controller.group;

import com.laiketui.app.api.groupBuy.GroupBuyService;
import com.laiketui.core.annotation.ParamsMapping;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.root.annotation.HttpApiMethod;
import com.laiketui.core.domain.Result;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.core.lktconst.GloabConst;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * 插件-拼团
 *
 * @author Trick
 * @date 2021/2/20 11:12
 */
//@Api(tags = "插件-拼团")
//@RestController
//@RequestMapping("/groupBuy")
public class GroupBuyController {

    @Autowired
    private GroupBuyService groupBuyService;

    @ApiOperation("拼团首页列表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "navType", value = "查询类型 1=查询活动结束+进行中的活动", dataType = "int", paramType = "form")
    })
    @PostMapping("/grouphome")
    @HttpApiMethod(urlMapping = "app.groupbuy.grouphome")
    public Result index(MainVo vo, Integer navType) {
        try {
            return Result.success(groupBuyService.grouphome(vo, navType));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("获取拼团商品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "activityId", value = "商品活动id", dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "platformActivityId", value = "平团活动id", dataType = "int", paramType = "form")
    })
    @PostMapping("/getgoodsdetail")
    @HttpApiMethod(urlMapping = "app.groupbuy.getgoodsdetail")
    public Result getgoodsdetail(MainVo vo, @ParamsMapping("pro_id") int goodsId, @ParamsMapping("activity_no") int activityId,
                                 @ParamsMapping("platform_activities_id") int platformActivityId) {
        try {
            return Result.success(groupBuyService.getgoodsdetail(vo, goodsId, activityId, platformActivityId));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("查询拼团订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderType", value = "notpay=未付款 grouping=未发货 success=待收货 status=待收货", dataType = "int", paramType = "form")
    })
    @PostMapping("/groupOrder")
    @HttpApiMethod(urlMapping = "app.groupbuy.grouporder")
    public Result grouporder(MainVo vo, @ParamsMapping("order_type") String orderType) {
        try {
            return Result.success(groupBuyService.grouporder(vo, orderType));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("拼团订单明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "order_id", value = "订单id", required = true, dataType = "int", paramType = "form")
    })
    @PostMapping("/orderDetails")
    @HttpApiMethod(urlMapping = "app.groupbuy.order_details")
    public Result orderDetails(MainVo vo, @ParamsMapping("order_id") int orderId) {
        try {
            return Result.success(groupBuyService.orderDetails(vo, orderId));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("拼团明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderno", value = "订单号", required = true, dataType = "int", paramType = "form")
    })
    @PostMapping("/group_other_detail")
    @HttpApiMethod(urlMapping = "app.groupbuy.group_other_detail")
    public Result groupDetail(MainVo vo, @ParamsMapping({"oid"}) String orderno) {
        try {
            return Result.success(groupBuyService.grouporderDetail(vo, orderno));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("取消我的拼团的未付款订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "order_id", value = "订单id", required = true, dataType = "int", paramType = "form")
    })
    @PostMapping("/removeGroupOrder")
    @HttpApiMethod(urlMapping = {"app.groupbuy.removeGroupOrder", "app.groupbuy.del_order"})
    public Result removeGroupOrder(MainVo vo, @ParamsMapping("order_id") int orderId) {
        try {
            return Result.success(groupBuyService.removeGroupOrder(vo, orderId));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("发货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sNo", value = "订单号", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "expressId", value = "快递公司Id", required = true, dataType = "int", paramType = "form"),
            @ApiImplicitParam(name = "courierNum", value = "快递单号", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "sNo", value = "订单号", required = true, dataType = "String", paramType = "form")
    })
    @PostMapping("/deliveryGood")
    @HttpApiMethod(urlMapping = {"app.groupbuy.deliveryGood"})
    public Result deliveryGood(MainVo vo, String sNo, @ParamsMapping("express_id") Integer expressId, @ParamsMapping("courier_num") String courierNum) {
        try {
            groupBuyService.deliveryGood(vo, sNo, expressId, courierNum);
            return Result.success(GloabConst.ManaValue.MANA_VALUE_SUCCESS);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }

    @ApiOperation("收货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderno", value = "订单号", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "rType", value = "售后状态", required = true, dataType = "int", paramType = "form")
    })
    @PostMapping("/receiveGood")
    @HttpApiMethod(urlMapping = {"app.groupbuy.receive_good"})
    public Result receiveGood(MainVo vo, String orderno, Integer rType) {
        try {
            return Result.success(groupBuyService.okOrder(vo.getStoreId(), vo.getAccessId(), orderno, rType));
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }


    @ApiOperation("拼团订单的订单拆分")
    @PostMapping("/goGroupLeaveSettlement")
    @HttpApiMethod(urlMapping = "app.groupbuy.goGroupLeaveSettlement")
    public Result grouporderDetail(MainVo vo) {
        try {
            //拼团订单无需拆分
            return Result.success(GloabConst.ManaValue.MANA_VALUE_SUCCESS);
        } catch (LaiKeAPIException e) {
            return Result.error(e.getCode(), e.getMessage());
        }
    }
}
